package org.jash.shop2112.user

import androidx.core.widget.addTextChangedListener
import com.alibaba.android.arouter.facade.annotation.Route
import org.jash.shop2112.databinding.ActivityRegisterBinding
import org.jash.shop2112.mvvm.BaseActivity
import org.jash.shop2112.utils.log

@Route(path = "/shop/register")
class RegisterActivity :  BaseActivity<ActivityRegisterBinding, RegisterViewModel>() {
    val map = mutableMapOf<String, String>()
    override fun initData() {
        viewModel.userLiveData.observe(this) {
            finish()
        }
    }

    override fun initView() {
        binding.user = map
        binding.register.setOnClickListener {
            viewModel.register(map)
        }
        binding.repassword.editText?.addTextChangedListener {
            if(map["password"] != map["repassword"]) {
                binding.repassword.error = "两次密码不一致"
                binding.repassword.isErrorEnabled = true
            } else {
                binding.repassword.isErrorEnabled = false
            }
        }
        setSupportActionBar(binding.toolbar)
        supportActionBar?.setDisplayHomeAsUpEnabled(true)
    }

}